#@layoutT('')
#define main()
<div class="container-wrap">

    <table id="maingrid" lay-filter="maingrid"></table>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button id='refreshBtn_' class="layui-btn  layui-btn-sm">
                <i class="layui-icon">&#xe669;</i> 刷新
            </button>
        </div>
    </script>
</div>
#end

#define js()
<script>
    var userCode="#(vs.code)";
    var groupId = "#(groupId)"
    layui.use(['upload'], function () {
        var $ = layui.jquery
            ,upload = layui.upload;
        gridArgs.title = '';
        gridArgs.dataId = 'id';
        gridArgs.deleteUrl = '#(path)/user/upload/file/delete';
        gridArgs.updateUrl = '#(path)/user/upload/file/edit/';
        gridArgs.addUrl = '#(path)/user/upload/file/add';
        gridArgs.gridDivId = 'maingrid';
        initGrid({
            id: 'maingrid'
            , elem: '#maingrid'
            , toolbar: '#toolbar'
            , cellMinWidth: 100
            , cols: [[
                {title: '主键', field: 'id', width: 35, checkbox: true},
                {title: '序号', type: 'numbers', width: 35},
                {title: '用户名', field: 'user_code'},
                {title: '文件名称', field: 'name'},
                {title: '激活码', field: 'active_code'},
                {title: '唯一标识', field: 'identifier'},
                {title: '应用名称', field: 'app_name'},
                {title: '应用版本', field: 'app_version'},
                {title: '运行次数', field: 'run_time', edit: 'text'},
                {title: '创建时间', field: 'create_time'},
                {title: '额外参数', field: 'extra_params', edit: 'text'}
            ]]
            , done: function(res, curr, count){//表格加载完成后，对上传按钮进行渲染
                var tableId = this.id;
                var tableElem = this.elem;
                //table render出来实际显示的table组件
                var tableViewElem = tableElem.next();
                //渲染当前页面的所有upload组件
                upload.render({
                    elem: tableViewElem.find('.up_file')
                    ,url: '/user/upload/file/uploadFile'
                    ,accept: 'file'
                    ,data:{}
                    ,before: function(obj){ //obj包含信息，跟choose回调完全一致。在传值之前先获取id
                        var tableElem = this.item;
                        id = tableElem.attr('value');
                        layer.load(); //上传loading
                    }
                    ,data: {
                        id: function () {//data中写值的时候，要用动态获取的方式，即写个function的方式，不然直接写获取不到相应的值。
                            return id;
                        }
                    }
                    ,done: function (res) {
                        layer.closeAll('loading'); //关闭loading
                        layer.msg('上传成功');
                    }
                    ,error: function(index, upload){
                        layer.closeAll('loading'); //关闭loading
                        layer.msg('上传失败，请重试');
                    }
                });
            }
            , url: "#(path)/user/upload/file/listByGroupId?groupId=" + groupId
            , searchForm: 'searchForm'
        });
    });
</script>


<script type="text/html" id="numToFileType">
    #[[
    {{# if(d.type==1){ }}
    普通场景
    {{# } }}

    {{# if(d.type==2){ }}
    昙花场景
    {{# } }}
    ]]#
</script>

#end

#define layuiFunc()
    //监听单元格编辑
    table.on('edit(maingrid)', function(obj){
        var value = obj.value //得到修改后的值
        ,data = obj.data //得到所在行所有键值
        ,field = obj.field; //得到字段
        var params=value;

        var params = {
           "userRecordParam.record_id": data.id,
           "userRecordParam.group_id": groupId
        };
        params["userRecordParam."+field] = value;
        params["type"] = field;
        $.post("#(path)/task/updateFieldValue", param(params)

        ,function(feedback){
            $(".layui-laypage-btn").click();
            layer.msg(feedback.msg);
        });
    });
#end






